package com.mobile.struts.action.grid;

import com.mobile.business.grid.GridBusiness;
import com.mobile.business.grid.IGridBusiness;
/**
 * 此类为GridAction<T>的工具类
 * @author hf
 *
 * @param <T>
 */
public class GridActionUtil<T> {
	private String title;
	private String jsSrc;
	private String[] fields;
	private T pojo;
	private String className;
	private IGridBusiness<T> gridBusiness;
	private IGridBusiness<T> gridBusinessProxy;
	public GridActionUtil(String title, String jsSrc, T pojo) {
		super();
		this.title = title;
		this.jsSrc = jsSrc;
		this.pojo = pojo;
		if(pojo!=null){
			this.className=pojo.getClass().getName();
		}
	}

	/**
	 * 
	 * @param title				页面的title
	 * @param jsSrc				js的地址
	 * @param fields			输出到ajax的字段
	 * @param pojo				pojo样本类
	 */
	public GridActionUtil(String title, String jsSrc, String[] fields,
			T pojo) {
		super();
		this.title = title;
		this.jsSrc = jsSrc;
		this.fields = fields;
		this.pojo = pojo;
		this.className=pojo.getClass().getName();
		this.gridBusiness=new GridBusiness<T>(this.pojo);
	}
	
	/**
	 * 
	 * @param title				页面的title
	 * @param jsSrc				js的地址
	 * @param fields			输出到ajax的字段
	 * @param pojo				pojo样本类
	 * @param gridBusiness		业务类
	 */
	public GridActionUtil(String title, String jsSrc, String[] fields,
			T pojo,IGridBusiness<T> gridBusiness) {
		super();
		this.title = title;
		this.jsSrc = jsSrc;
		this.fields = fields;
		this.pojo = pojo;
		this.className=pojo.getClass().getName();
		this.gridBusiness=gridBusiness;
	}
	/**
	 * 
	 * @param title				页面的title
	 * @param jsSrc				js的地址
	 * @param fields			输出到ajax的字段
	 * @param className			要实例化类的类名
	 */
	public GridActionUtil(String title, String jsSrc, String[] fields,
			String className) {
		super();
		this.title = title;
		this.jsSrc = jsSrc;
		this.fields = fields;
		this.className = className;
		T pojo=getPojo();
		this.gridBusiness=new GridBusiness<T>(this.pojo);
	}
	/**
	 * 
	 * @param title				页面的title
	 * @param jsSrc				js的地址
	 * @param fields			输出到ajax的字段
	 * @param className			要实例化类的类名
	 * @param gridBusiness		业务类
	 */
	public GridActionUtil(String title, String jsSrc, String[] fields,
			String className,IGridBusiness<T> gridBusiness) {
		super();
		this.title = title;
		this.jsSrc = jsSrc;
		this.fields = fields;
		this.className = className;
		this.gridBusiness=gridBusiness;
	}
	/**
	 * 获得业务处理类
	 * @return
	 */
	public IGridBusiness<T> getPib() {
		/*// TODO Auto-generated method stub
		
		 * 创建IPageImplBusiness<SortManage>的动态代理类
		 
		
		//IGridBusiness<T> pib=new GridBusiness<T>(pojo);
		if(this.gridBusinessProxy==null){
			GridBusinessProxy hanlder=new GridBusinessProxy(this.gridBusiness);
			IGridBusiness<T> proxy=(IGridBusiness<T>)Proxy.newProxyInstance(
					this.gridBusiness.getClass().getClassLoader(),
					this.gridBusiness.getClass().getInterfaces(),
					hanlder);
			this.gridBusinessProxy=proxy;
		}
		return this.gridBusinessProxy;*/
		return this.gridBusiness;
	}
	
	public void setPib(IGridBusiness<T> gridBusiness) {
		this.gridBusiness=gridBusiness;
	}
	
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getJsSrc() {
		return jsSrc;
	}

	public void setJsSrc(String jsSrc) {
		this.jsSrc = jsSrc;
	}

	public String[] getFields() {
		return fields;
	}

	public void setFields(String[] fields) {
		this.fields = fields;
	}

	public T getPojo() {
		T pojo=null;
		try {
			pojo= (T)Class.forName(className).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return pojo;
	}

	public void setPojo(T pojo) {
		this.pojo = pojo;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}
}
